﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Nirvana
{
    public class WaitLoadScriptable : CustomYieldInstruction
    {
        private ScriptableCache cache;
        public string Error { get; private set; }
        public ScriptableObject LoadedObject { get; private set; }

        public WaitLoadScriptable(ScriptableCache cache)
        {
            this.cache = cache;
        }


        public override bool keepWaiting
        {
            get
            {
                if (!string.IsNullOrEmpty(this.cache.Error))
                {
                    this.Error = this.cache.Error;
                    return false;
                }
                if (this.cache.IsNotNull())
                {
                    this.LoadedObject = this.cache.GetObject();
                    return false;
                }
                return true;
            }
        }

    }
}

